<?php
/**
 * Created by PhpStorm.
 * User: fengbob
 * Date: 2018/2/12
 * Time: 15:07
 */
$web = \yii\helpers\Url::base();
?>


<div class="main-title">
    <div class="title-txt">首页推荐</div>
</div>

<!--search-->
<!--<div class="panel panel-frame panel-operat">-->
<!--    <div class="panel-body">-->
<!--        <div class="panel-content">-->
<!--            <input type="text" class="form-control search-box" placeholder="名称" id="name" name="name"-->
<!--                   value="">-->
<!--            <a href="javascript:search()" type="button" class="btn btn-warning search-icon">-->
<!--                <div class="btn-icon"></div>-->
<!--                <div class="btn-text">搜索</div>-->
<!--            </a>-->
<!--            <a href="javascript:editData()" type="button" class="btn btn-primary add-icon ">-->
<!--                <div class="btn-icon"></div>-->
<!--                <div class="btn-text">添加</div>-->
<!--            </a>-->
<!--        </div>-->
<!--    </div>-->
<!--</div>-->


<!--list-->
<div class="panel panel-frame" id="data_form"">
    <div class="table-responsive" >
        <table class="table table-bordered table-hover">
            <thead>
            <tr>
                <th>分类名称</th>
                <th>排序(数字越大越考前)</th>
                <th>显示商品数量</th>
            </tr>
            </thead>
            <tbody>
            <input id="main_page_id" value="<?=$main_page->id?>" hidden="hidden"/>
                <tr>
                    <td>热销商品</td>
                    <td>
                        <select ID="hot_sort">
                            <?php
                              $i = 0;
                            for($i=0;$i<=20;$i++){
                                ?><option value="<?=$i?>"
                                <?php
                                 if($main_page->hot_goods_sort == $i){
                                     ?> selected="selected"
                                <?php
                                 }
                                ?>
                                ><?=$i?></option><?
                            }
                            ?>
                        </select>
                    </td>

                    <td>
                        <select id="hot_num">
                            <?
                            for($i=0;$i<=20;$i++){
                                ?><option value="<?=$i?>"
                                <?php
                                if($main_page->hot_goods_num == $i){
                                    ?> selected="selected"
                                    <?php
                                }
                                ?>
                                ><?=$i?></option><?
                            }
                            ?>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td>新品上市</td>
                    <td>
                        <select id="newest_sort">
                            <?
                            for($i=0;$i<=20;$i++){
                                ?><option value="<?=$i?>"
                                <?php
                                if($main_page->newest_goods_sort == $i){
                                    ?> selected="selected"
                                    <?php
                                }
                                ?>
                                ><?=$i?></option><?
                            }
                            ?>
                        </select>
                    </td>

                    <td>
                        <select id="newest_num">
                            <?
                            for($i=0;$i<=20;$i++){
                                ?><option value="<?=$i?>"
                                <?php
                                if($main_page->newest_goods_num == $i){
                                    ?> selected="selected"
                                    <?php
                                }
                                ?>
                                ><?=$i?></option><?
                            }
                            ?>
                        </select>
                    </td>
                </tr>


                <tr>
                    <td>推荐商品</td>
                    <td>
                        <select id="recommend_sort">
                            <?
                            for($i=0;$i<=20;$i++){
                                ?><option value="<?=$i?>"
                                <?php
                                if($main_page->recommend_goods_sort == $i){
                                    ?> selected="selected"
                                    <?php
                                }
                                ?>
                                ><?=$i?></option><?
                            }
                            ?>
                        </select>
                    </td>

                    <td>
                        <select id="recommend_num">
                            <?
                            for($i=0;$i<=20;$i++){
                                ?><option value="<?=$i?>"
                                <?php
                                if($main_page->recommend_goods_num == $i){
                                    ?> selected="selected"
                                    <?php
                                }
                                ?>
                                ><?=$i?></option><?
                            }
                            ?>
                        </select>
                    </td>
                </tr>


                <tr>
                    <td>包邮商品</td>
                    <td>
                        <select id="free_express_sort">
                            <?
                            for($i=0;$i<=20;$i++){
                                ?><option value="<?=$i?>"
                                <?php
                                if($main_page->free_express_goods_sort == $i){
                                    ?> selected="selected"
                                    <?php
                                }
                                ?>
                                ><?=$i?></option><?
                            }
                            ?>
                        </select>
                    </td>

                    <td>
                        <select id="free_express_num">
                            <?
                            for($i=0;$i<=20;$i++){
                                ?><option value="<?=$i?>"
                                <?php
                                if($main_page->free_express_goods_num == $i){
                                    ?> selected="selected"
                                    <?php
                                }
                                ?>
                                ><?=$i?></option><?
                            }
                            ?>
                        </select>
                    </td>
                </tr>


                <tr>
                    <td>促销商品</td>
                    <td>
                        <select id="promotion_sort">
                            <?
                            for($i=0;$i<=20;$i++){
                                ?><option value="<?=$i?>"
                                <?php
                                if($main_page->promotion_goods_sort == $i){
                                    ?> selected="selected"
                                    <?php
                                }
                                ?>
                                ><?=$i?></option><?
                            }
                            ?>
                        </select>
                    </td>

                    <td>
                        <select id="promotion_num">
                            <?
                            for($i=0;$i<=20;$i++){
                                ?><option value="<?=$i?>"
                                <?php
                                if($main_page->promotion_goods_num == $i){
                                    ?> selected="selected"
                                    <?php
                                }
                                ?>
                                ><?=$i?></option><?
                            }
                            ?>
                        </select>
                    </td>
                </tr>

            </tbody>
        </table>
    </div>
    <!--    <div class="table-pagination">-->
    <!--        --><?//= \app\widgets\LinkPagerExt::widget(['pagination' => $pagination]) ?>
    <!--    </div>-->
</div>

<div class="button-container">
    <button type="button" class="btn" onclick="saveData()" >保存</button>
</div>

<!--edit-->
<!--<div class="modal fade" id="dataModalEdit" tabindex="1" role="dialog"-->
<!--     aria-labelledby="dataModalEditLabel">-->
<!--    <div class="modal-dialog modal-lg" role="document">-->
<!--        <div class="modal-content">-->
<!--            <div class="modal-header">-->
<!--                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span-->
<!--                        aria-hidden="false">&times;</span></button>-->
<!--                <h4 class="modal-title" id="dataModalEditLabel">--><?//= $this->title . '编辑' ?><!--</h4>-->
<!--            </div>-->
<!--            <div id="modalEdit" class="modal-body">-->
<!--            </div>-->
<!--            <div class="modal-footer">-->
<!--                <a class="btn btn-primary" onclick="saveData()"><i class="fa fa-save"></i> 保存-->
<!--                </a>-->
<!--                <a class="btn btn-cancel" data-dismiss="modal"><i class="fa fa-remove"></i> 取消-->
<!--                </a>-->
<!--            </div>-->
<!--        </div>-->
<!--    </div>-->
<!--</div>-->


<script type="text/javascript">

    function search() {
        var name = $("#name").val();
        var href = window.location.href;
        var index = href.indexOf("?page=");
        if (index > 0) {
            href = href.substr(0, index);
        }
        var href_str = href + "?page=1";

        if (name != '' && name != null) {
            href_str = href_str + "&name=" + name;
        }
        window.location.href = href_str;
    }

    function editData(id) {
        $('#dataModalEdit').modal({
            keyboard: false, backdrop: 'static', show: false
        });

        $("#dataModalEdit").modal('show');
        $("#dataModalEdit").on('show');
        var data = {};
        if (id != undefined) {
            data.id = id;
        }

        $("#dataModalEdit").find("#modalEdit").html('正在加载数据...');

        requestHtml('swiper-partial', data, true, function (responseHtml) {
            $("#dataModalEdit").find("#modalEdit").html(responseHtml);
        });
    }

    function saveData() {
//        alert($("#data_form").find("#rexiao_num").val());

        var hot_sot = $("#data_form").find("#hot_sort").val();
        var hot_num = $("#data_form").find("#hot_num").val();
        var newest_sort = $("#data_form").find("#newest_sort").val();
        var newest_num = $("#data_form").find("#newest_num").val();
        var recommend_sort = $("#data_form").find("#recommend_sort").val();
        var recommend_num = $("#data_form").find("#recommend_num").val();
        var free_express_num = $("#data_form").find("#free_express_num").val();
        var free_express_sort = $("#data_form").find("#free_express_sort").val();
        var promotion_num = $("#data_form").find("#promotion_num").val();
        var promotion_sort = $("#data_form").find("#promotion_sort").val();


        var data = {};

        data.id = $("#data_form").find("#main_page_id").val();
        data.hot_goods_num = hot_num;
        data.newest_goods_num = newest_num;
        data.recommend_goods_num = recommend_num;
        data.free_express_goods_num = free_express_num;
        data.promotion_goods_num = promotion_num;
        data.hot_goods_sort = hot_sot;
        data.newest_goods_sort =newest_sort ;
        data.recommend_goods_sort = recommend_sort;
        data.free_express_goods_sort = free_express_sort;
        data.promotion_goods_sort = promotion_sort;

//        debugger(alert('in2 !'));
//        debugger;
        requestJson("main-page-save-handler", data, true, function (response) {
//            alert('in3 !');

//            alert( response.status);
            if (response.status == 0) {
                alert(response.message);
                search();
            }
            else {
                errorDialog(response.message);
            }
        },function (response) {
            alert('in error');
        })
    }

    function deleteData(id) {
//        alert("待。。。");
//        return false;
        confirmDialog(id, null, function (id) {
            var data = {};
            data.id = id;
            requestJson("ad-delete-handler", data, true, function (response) {
                if (response.status == 0) {
                    search();
                } else {
                    errorDialog(response.message);
                }
            });
        });
    }

</script>